package com.zj.service.bank;

import java.util.UUID;

import javax.jms.BytesMessage;
import javax.jms.Message;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;


import com.zj.common.BuilderParam;
import com.zj.common.TiripPackage;
import com.zj.common.mq.SendMessage;
import com.zj.common.mq.SsReciveMessage;
import com.zj.common.xml.XmlUtil;
import com.zj.request.JhSyYhCbcxRqBody;
import com.zj.request.body.JhSyYhCbcxReqBody;
import com.zj.request.head.JhSyYhcxjfTyReqHead;
import com.zj.response.JhSyYhcxjfTyResBody;

/**
 * 社保查詢
 * 
 * @author lu
 *
 */
public class BnkChrgInsrInfoQryService {
	private static final Logger logger = LoggerFactory.getLogger(BnkChrgInsrInfoQryService.class);
	@Autowired
	SendMessage sendMessage;

	@Autowired
	SsReciveMessage ssReciveMessage;

	public void query() throws Exception {
		JhSyYhCbcxRqBody open = new JhSyYhCbcxRqBody();
		JhSyYhcxjfTyReqHead head = new JhSyYhcxjfTyReqHead("20190305");
		open.setHead(head);

		JhSyYhCbcxReqBody jhSyYhCbcxReqBody = new com.zj.request.body.JhSyYhCbcxReqBody("201", "430111196402120016",
				"胡迪强");
		open.setBody(jhSyYhCbcxReqBody);
		String str = BuilderParam.getJhSyYhcxjfTy(open);
		System.out.println(str);
		String messageId = sendMessage.sendSs(UUID.randomUUID().toString(), str);
		Message message = ssReciveMessage.reciveFromCorrelationID(messageId);
		BytesMessage msg = (BytesMessage) message;

		byte[] bs = new byte[(int) msg.getBodyLength()];
		String resp = null;
		while (msg.readBytes(bs) != -1) {
			resp = new String(bs, "GBK");

		}
		System.out.println(resp);
		TiripPackage tri = XmlUtil.toBean(resp, TiripPackage.class);
		JhSyYhcxjfTyResBody openResp = XmlUtil.toBean(XmlUtil.subCdata(tri), JhSyYhcxjfTyResBody.class);

		System.out.println(tri);
	}

}
